package com.woniu.service.impl;

import com.woniu.dao.MenuDao;
import com.woniu.entity.vo.MenuVo;
import com.woniu.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    MenuDao menuMapper;
    @Override
    public List<MenuVo> selectMenuByUserName(String userName) {
        List<MenuVo> mlist = menuMapper.selectMenuByUserName(userName);
        List<MenuVo> oneList = new ArrayList();
        for (MenuVo menu : mlist) {
            if(menu.getPid()==0){
                oneList.add(menu);
            }
        }
        for (MenuVo menu : oneList) {
            ArrayList<MenuVo> twoList = new ArrayList<>();
            for (MenuVo m : mlist) {
                if (menu.getId()==m.getPid()){
                    twoList.add(m);
                }
            }
            menu.setChildren(twoList);
        }
        return oneList;
    }

}
